<?php

/**

 * Static content controller.

 *

 * This file will render views from views/pages/

 *

 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)

 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)

 *

 * Licensed under The MIT License

 * For full copyright and license information, please see the LICENSE.txt

 * Redistributions of files must retain the above copyright notice.

 *

 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)

 * @link          http://cakephp.org CakePHP(tm) Project

 * @package       app.Controller

 * @since         CakePHP(tm) v 0.2.9

 * @license       http://www.opensource.org/licenses/mit-license.php MIT License

 */



App::uses('AppController', 'Controller');

App::uses('L10n', 'I18n');

/**

 * Static content controller

 *

 * Override this controller by placing a copy in controllers directory of an application

 *

 * @package       app.Controller

 * @link http://book.cakephp.org/2.0/en/controllers/pages-controller.html

 */

class PagesController extends AppController {



/**

 * This controller does not use a model

 *

 * @var array

 */

	public $uses = array();



/**

 * Displays a view

 *

 * @return void

 * @throws NotFoundException When the view file could not be found

 *	or MissingViewException in debug mode.

 */

    public function beforeFilter() {

        $this->Auth->allow('changeLanguage','index','about','contact','contact_us','listing_type','pricing','twitts');

        parent::beforeFilter();

    }



    public function admin_changeLanguage($lng) { // Change language method

	$this->changeLanguage($lng);

	}

    public function changeLanguage($lng) { // Change language method

        if(isset($this->availableLanguages[$lng])) { // If we support this language (see /app/Config/global.php)

            parent::setLang($lng); // call setLang() from AppController

			$this->L10n = new L10n();

		//pr($this->L10n->direction);

		//pr($this->language);

		//pr($this->L10n->get($this->language));

//		echo CACHE;exit;

		@unlink(CACHE.'cake_element__side-bar_cache_callbacks');

		@unlink(CACHE.'cake_element__side-bar-more-agents_cache_callbacks');		
		@unlink(CACHE.'cake_element__latest-posts_cache_callbacks');		
		@unlink(CACHE.'cake_blog_tags');		
		@unlink(CACHE.'cake_blog_categories');		
		@unlink(CACHE.'cake_blog_archives');		

		$L10n_catalog 	=	$this->L10n->catalog($lng);

 		$this->Session->write('Config.language_catalog', $L10n_catalog); // write our language to session

            $this->Session->setFlash(__('The language has been changed to %s', $this->availableLanguages[$lng])); // Send a success flash message

        } else {

            throw new NotFoundException(__('Language %s is not supported', $lng)); // Throw a not found exception

        }



        $this->redirect($this->referer()); // redirect the user to the last page (referer)

        //$this->redirect(array('controller'=>'pages')); // redirect the user to the last page (referer)

    }

		public function index() {
			$website_name	=	($this->viewVars['websiteSettings']['website_name']);
		 	$this->set('title_for_layout', 'Wellcome to '.$website_name);
			$this->LoadModel('Property');
			$this->LoadModel('PropertyType');
			$this->LoadModel('City');

			$featured_Properties	=	$this->Property->find('all',array('limit'=>10, 'order'=>'RAND()','conditions' => array('User.expiry_date >= ' => date('Y-m-d H:i'),'User.active' => 1,'Property.active' => 1)));
			$Properties	=	$this->Property->find('all',array('limit'=>5, 'order'=>'Property.id desc ','conditions' => array('User.expiry_date >= ' => date('Y-m-d H:i'),'User.active' => 1,'Property.active' => 1)));
			$this->set(compact('Properties','featured_Properties'));

			$getPropertyType	= 	$this->PropertyType->getPropertyType();
			$getCity	= 	$this->City->getCity();

			$this->set(compact('getPropertyType','getCity'));

			}





		public function about() { $this->set('title_for_layout', 'About Us');
		
		$this->loadModel('Twitter.Twitter');
$twitter = $this->Twitter->get();

//pr($twitter);

foreach($twitter as $twitt)
pr($twitt->user->screen_name);


		}
		
		public function twitts() { 
		
		$this->loadModel('Twitter.Twitter');
		$twitteruser = $this->Twitter->get();
		
//pr($twitteruser);
//$this->autoRender = false;
$this->layout = 'ajax';
$this->set('twitteruser', $twitteruser);

		}

		public function contact() { $this->set('title_for_layout', 'Contact Us');}



		public function listing_type($listing_type='list') {

		$this->request->onlyAllow('post', 'listing_type');

		$this->Session->write('List_type',$listing_type);

		//$this->Session->delete('List_type');

       return $this->redirect($this->referer()); // redirect the user to the last page (referer)

		

		

			}


	public function pricing(){ 
		$this->set('title_for_layout', 'Pricing');	
		$this->loadModel('Package');
		$Packages	=	$this->Package->find('all',array('order'=>'Package.sort_by desc'));
		
		$this->set('Packages', $Packages);


	}



}

